package com.jia.activity;

import android.app.Activity;
import android.content.res.AssetFileDescriptor;
import android.content.res.AssetManager;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import com.jia.R;

import java.io.IOException;

/**
 * @Author: xiuyajia
 * @Date: 12/3/13 4:33 PM
 */
public class RawResTest extends Activity {
    private MediaPlayer mediaPlayer1 = null;
    private MediaPlayer mediaPlayer2 = null;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.rawrestest);

        mediaPlayer1 = MediaPlayer.create(this, R.raw.bomb);

        AssetManager assetManager = getAssets();
        try {
            AssetFileDescriptor assetFileDescriptor = assetManager.openFd("shot.mp3");
            mediaPlayer2 = new MediaPlayer();
            mediaPlayer2.setDataSource(assetFileDescriptor.getFileDescriptor());
            mediaPlayer2.prepare();
        } catch (IOException e) {
            e.printStackTrace();
        }


        Button playRaw = (Button) findViewById(R.id.playRaw);
        playRaw.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                mediaPlayer1.start();
            }
        });

        Button playAsset = (Button) findViewById(R.id.playAsset);
        playAsset.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                mediaPlayer2.start();
            }
        });

    }
}
